package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {
    @Autowired
    private UserService us;
    @GetMapping("/user/login/{name}/{pwd}")
    public boolean login(@PathVariable("name") String name, @PathVariable("pwd") String pwd, HttpSession session){
        System.out.println(name);
        System.out.println(pwd);
        boolean login = us.login(name, pwd);
        if (login){
            User user = us.selectByUser(name,pwd);
            session.setAttribute("user",user);
            return true;
        }else{
            return false;
        }
    };
}
